package nowcoder.offer;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

/**
 * 对称的二叉树
 *
 * @author briarbear
 * @blog https://briarbear.github.io
 * @date 2018-08-29 15:54
 */
public class isSymmetrical {



    boolean solution(TreeNode pRoot){
        if(pRoot == null) return true;
        return check(pRoot.left,pRoot.right); //比较两个二叉树

    }

    /**
     * 验证两个二叉树是否镜像相等
     */
    public boolean check(TreeNode node,TreeNode copy){
        if (node == null && copy == null) return true;
        if (!(node != null && copy != null)) return false;

        if (node.val != copy.val) return false;

        return check(node.left,copy.right) && check(node.right,copy.left);
    }


    public static void main(String[] args) {
        TreeNode root = new TreeNode(8);
        root.left = new TreeNode(6);
        root.left.left = new TreeNode(5);
        root.left.right = new TreeNode(7);

        root.right = new TreeNode(9);
        root.right.left = new TreeNode(7);
        root.right.right = new TreeNode(5);

        System.out.println(new isSymmetrical().solution(root));

    }
}
